www.gusucode.com > VC++全能邮件发送组件smtp.lib V2.0源码程序 > VC++全能邮件发送组件smtp.lib V2.0源码程序\code\SMTPLIB完整示例\SMTPLIB完整示例Dlg.cpp
// SMTPLIB完整示例Dlg.cpp : implementation file // Download by http://www.NewXing.com #include "stdafx.h" #include "SMTPLIB完整示例.h" #include "SMTPLIB完整示例Dlg.h" #include "smtp.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSMTPLIBDlg dialog CSMTPLIBDlg::CSMTPLIBDlg(CWnd* pParent /*=NULL*/) : CDialog(CSMTPLIBDlg::IDD, pParent) { //{{AFX_DATA_INIT(CSMTPLIBDlg) m_html = FALSE; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CSMTPLIBDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSMTPLIBDlg) DDX_Check(pDX, IDC_HTML, m_html); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSMTPLIBDlg, CDialog) //{{AFX_MSG_MAP(CSMTPLIBDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON3, OnSend) ON_BN_CLICKED(IDC_BUTTON1, Onfile) ON_BN_CLICKED(IDC_BUTTON2, OnDelFile) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSMTPLIBDlg message handlers BOOL CSMTPLIBDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here SetDlgItemText(IDC_SMTP,"smtp.163.com"); return TRUE; // return TRUE unless you set the focus to a control } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CSMTPLIBDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CSMTPLIBDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CSMTPLIBDlg::OnSend() { #pragma comment(lib,"smtp.lib") UpdateData(TRUE); CString strsmtp,user,password,postmail,recvmail,title,text,file; bool html=m_html; GetDlgItemText(IDC_SMTP,strsmtp); GetDlgItemText(IDC_USER,user); GetDlgItemText(IDC_PASSWORD,password); GetDlgItemText(IDC_POSTMAIL,postmail); GetDlgItemText(IDC_RECVMAIL,recvmail); GetDlgItemText(IDC_TITLE,title); GetDlgItemText(IDC_TEXT,text); GetDlgItemText(IDC_FILE,file); int zt=0; smtp send; zt=send.link(strsmtp,user,password,postmail,recvmail,title,text,file,html); if(zt==0) MessageBox("邮件发送成功!"); if(zt==1) MessageBox("邮件发送失败!"); if(zt==2) MessageBox("连接服务器失败!"); if(zt==3) MessageBox("用户名或密码失败!"); } CString CSMTPLIBDlg::getfile() { //打开文件对话框和保存对话框 CString m_filename; LPCTSTR filters = _T("All Files(*.*)|*.*"); CFileDialog fileDlg(TRUE,_T("*.*"),NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,filters); int result=fileDlg.DoModal(); if (result==IDOK) { m_filename=fileDlg.GetPathName(); } return m_filename; } void CSMTPLIBDlg::Onfile() { SetDlgItemText(IDC_FILE,getfile()); } void CSMTPLIBDlg::OnDelFile() { SetDlgItemText(IDC_FILE,""); }